﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LPV_POS.Module;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos
{
    public partial class mh_so : DevExpress.XtraEditors.XtraForm
    {
        CultureInfo culture;
        string str_lang = "";
        string str_thongbao = "";

        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang6_PhuThu).Assembly);
                bton_thoat_2.Text = rm.GetString("thoat", culture);
                bton_chon_2.Text = rm.GetString("chon", culture);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion

        public mh_so()

        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
        }
        public mh_so(Boolean ShowPassword)
        {
            InitializeComponent();
            if (ShowPassword)
                txt_ketqua.Properties.PasswordChar = '*';
        }
        public mh_so(string title)
        {
            InitializeComponent();
            this.Text = title;
            this.Text = ".";
        }
        float inoidung = 0;
        public mh_so(string title, int _inoidung)
        {
            InitializeComponent();
            this.Text = title;
            inoidung = _inoidung;
            this.Text = ".";
        }
        public mh_so(string title, float _inoidung)
        {
            InitializeComponent();
            this.Text = title;
            inoidung = _inoidung;
            this.Text = ".";
        }
        public mh_so(string title, int _inoidung,string btnChon_Text)
        {
            InitializeComponent();
            this.Text = title;
            this.Text = ".";
            inoidung = _inoidung;
            if (!string.IsNullOrEmpty(btnChon_Text.Trim()))
                bton_chon_2.Text = btnChon_Text.Trim();

        }
        public mh_so(Boolean ShowPassword, string title)
        {
            InitializeComponent();
            this.Text = title;
            //this.Text = ".";
            if (ShowPassword)
                txt_ketqua.Properties.PasswordChar = '*';
        }

        public EventHandler eClick = null;

        #region cac su kien
        private void bton_thoat_Click(object sender, EventArgs e)
        {
            Variable.str_so = "";
            Variable.int_close = -1;
            this.Close();

        }

        private void mh_so_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);

            txt_ketqua.Text = "";
            CancelButton = bton_thoat;

            if (Variable.pont_x > 0 || Variable.pont_y > 0)
                this.Location = new System.Drawing.Point(Variable.pont_x, Variable.pont_y);
            Variable.pont_x = 0;
            Variable.pont_y = 0;

            Variable.int_vitri = 0;
            Variable.str_position_frmso = "";
            if (inoidung > 0)
                txt_ketqua.Text = inoidung + "";
        }

        private void bton_0_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_0.Text;
        }


        private void bton_1_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_1.Text;
        }

        private void bton_2_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_2.Text;
        }

        private void bton_3_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_3.Text;
        }

        private void bton_4_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_4.Text;
        }

        private void bton_5_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_5.Text;
        }

        private void bton_6_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_6.Text;
        }

        private void bton_7_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_7.Text;
        }

        private void bton_8_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_8.Text;
        }

        private void bton_9_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_9.Text;
        }

        private void bton_00_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_00.Text;
        }

        private void bton_thapphan_Click(object sender, EventArgs e)
        {
            if (!this.btonSelected_Click(sender))
                txt_ketqua.Text += bton_thapphan.Text;
        }

        private void bton_xoa_Click(object sender, EventArgs e)
        {
            if (txt_ketqua.Text != "")
            {
                txt_ketqua.Text = txt_ketqua.Text.Substring(0, txt_ketqua.Text.Length - 1);
            }

        }
        Boolean btonSelected_Click(object sender)
        {
            DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)sender;
            if (txt_ketqua.SelectedText.Trim() != "")
            {
                txt_ketqua.SelectedText = btn.Text;
                return true;
            }
            return false;
        }
        private void txt_ketqua_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar))
                e.Handled = true;
        }

        private void bton_chon_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (txt_ketqua.Text != "")
                {
                    Variable.str_so = txt_ketqua.Text;
                    this.DialogResult = DialogResult.OK;
                    if (eClick != null)
                    {
                        this.eClick(this, null);
                        return;
                    }
                }
                else
                {
                    switch (str_lang)
                    {
                        case "vi-VN":
                            str_thongbao = "Vui lòng nhập số.";
                            break;
                        case "en-US":
                            str_thongbao = "Please enter password.";
                            break;
                    }
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("", str_thongbao, loaithongbao.canhbao.GetHashCode());
                    return;
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
            Variable.int_close = 1;
            this.Close();
        }
        #endregion

        private void bton_thoat_2_Click(object sender, EventArgs e)
        {
            Variable.str_so = "";
            Variable.int_close = -1;
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (txt_ketqua.Text != "")
                {
                    Variable.str_so = txt_ketqua.Text;
                    this.DialogResult = DialogResult.OK;
                    if (eClick != null)
                    {
                        this.eClick(this, null);
                        return;
                    }
                }
                else
                {
                    switch (str_lang)
                    {
                        case "vi-VN":
                            str_thongbao = "Vui lòng nhập số.";
                            break;
                        case "en-US":
                            str_thongbao = "Please enter password.";
                            break;
                    }
                    Mod_messagebox mess = new Mod_messagebox();

                    mess.messagebox_pos("", str_thongbao, loaithongbao.canhbao.GetHashCode());
                    return;
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
            Variable.int_close = 1;
            this.Close();
        }


        public int ShowForm()
        {
            this.ShowDialog();
            int i = 0;
            int.TryParse(txt_ketqua.Text, out i);
            return i;
        }
        public decimal ShowFormD()
        {
            this.ShowDialog();
            decimal i = 0;
            decimal.TryParse(txt_ketqua.Text, out i);
            return i;
        }

        public string ShowFormS()
        {
            this.ShowDialog();
            return txt_ketqua.Text;
        }
    }
}